﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace CPPEI.PM.Service.Model.Repository
{
    public class WorkStageRepository
    {
        private DbContext _dbContext;
        public WorkStageRepository(DbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public WorkStage Get(Guid id)
        {
            return _dbContext.Set<WorkStage>().SingleOrDefault(p => p.Id == id);
        }

        public List<WorkItem> GetWorkItemList(Guid projectId, Guid workSheetId)
        {
            return _dbContext.Set<WorkItem>().Join(_dbContext.Set<WorkItemRef>(),
                l => l.Id,
                r => r.WorkItemId,
                (l, r) => l).ToList();
        }

        public void Create(WorkStage workStage)
        {
            _dbContext.Set<WorkStage>().Add(workStage);
        }
    }
}
